package com.llp.javaweb.dao;

import com.llp.javaweb.mapper.ShopCartMapper;
import com.llp.javaweb.pojo.Product;
import com.llp.javaweb.pojo.UserProduct;
import com.llp.javaweb.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author llp
 * {@code @date} 2022年11月03日17:52
 */

public class ShopCartDao {

    public List<Product> getAllUserProduct(String userid) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ShopCartMapper shopCartMapper = sqlSession.getMapper(ShopCartMapper.class);
        List<UserProduct> allUserProduct = shopCartMapper.getAllUserProduct(userid);
                Set<Integer> set=new HashSet<>();
        for (int i = 0; i < allUserProduct.size(); i++) {
            set.add(allUserProduct.get(i).getProductid());
        }
        List<Product> productById = shopCartMapper.getProductById(set);
        return productById;

    }
}
